package com.z.sys.controller;

import com.z.common.aop.annotation.Log;
import com.z.common.aop.enums.BusinessType;
import com.z.common.web.base.BaseController;
import com.z.common.web.vo.response.Result;
import com.z.sys.entity.EmailConfig;
import com.z.sys.service.IEmailConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;


/**
 * 邮箱配置Controller
 *
 * @author z
 * @date 2023-12-27
 */
@Api(tags = "邮箱配置")
@RestController
@RequestMapping("/system/emailConfig")
public class EmailConfigController extends BaseController {

    private String prefix = "system/emailConfig";

    @Autowired
    private IEmailConfigService emailConfigService;

    /**
     * 修改邮箱配置
     */
    @GetMapping("/edit")
    @PreAuthorize("hasPermission('/sys/backConfig/edit','sys:backConfig:edit')")
    @ApiOperation(value = "修改页面")
    public ModelAndView edit(Long id, ModelMap map) {
        EmailConfig emailConfig = emailConfigService.getById(id);
        map.put("emailConfig", emailConfig);
        return jumpPage(prefix + "/edit");
    }

    /**
     * 修改邮箱配置
     */
    @ResponseBody
    @PutMapping("/update")
    @PreAuthorize("hasPermission('/sys/emailConfig/update','sys:emailConfig:edit')")
    @Log(title = "邮箱配置", describe = "修改邮箱配置数据", type = BusinessType.EDIT)
    @ApiOperation(value = "修改接口")
    public Result update(@RequestBody EmailConfig emailConfig) {
        return Result.decide(emailConfigService.updateById(emailConfig));
    }
}
